<template>
	<view class="content">
		<image class="logo" src="/static/logo.png" @click="goUserInfo"></image>
		<button @click="addClick">新增</button>
		<view class="text-area">
			<text class="title">{{title}}</text>
		</view>
		<view>
			<navigator url="/uni_modules/uni-id-pages/pages/login/login-withpwd">登录</navigator>
		</view>
		<view>
			<button @click="goUpdate">修改</button>
		</view>
	</view>
</template>

<script>
	const db = uniCloud.database()
	export default {
		data() {
			return {
				title: 'Hello'
			}
		},
		onLoad() {
			this.getData()
		},
		methods: {
			getData() {
				db.collection('article').get().then(res => {
					console.log(res, 'res')
				})
			},
			goUserInfo() {
				uni.navigateTo({
					url: '/uni_modules/uni-id-pages/pages/userinfo/userinfo'
				})
			},
			addClick() {
				db.collection('cloudDemo').add({
					title: 'unicloud',
					content: '888'
				}).then(res => {
					console.log(res, 'res')
					uni.showToast({
						title: '添加成功'
					})
				}).catch(err => {
					console.log(err.message, 'err')
					uni.showToast({
						icon: 'none',
						title: err.message
					})
				})
			},
			goUpdate() {
				db.collection('article').doc('64d43f9f652341bd642b00a9').update({
					title: 'uniapp学习'
				}).then(res => {
					console.log(res, 'res')
				}).catch(err => {
					uni.showToast({
						title: err.message,
						icon: 'none'
					})
				})
			}
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
</style>
